#{extends 'main.html' /}
#{set title:assignment.title /}
#{if flash.error}
<p>${flash.error}</p>
#{/if}
#{if flash.success}
<p>${flash.success}</p>
#{/if}
<h2>${assignment.title}</h2>
<h4>Deadline: <span class="formatTime">${assignment.deadline}</span></h4>
Your submissions:
<ol>
#{list items:submissions, as:'sub'}
	<li class="${sub.toGrade ? 'chosen' : ''}" style="padding:5px;border-radius:15px;">
		Submission made at: <span class="formatTime">${sub.time}</span>
		<div><a href="/download/submission?id=${sub.id}">${sub.getFile().getName()}</a></div>
		<div>
		#{if sub.toGrade}
		#{/if}#{elseif sub.time > sub.assignment.deadline}
		This submission was made after the deadline. You cannot pick it.
		#{/elseif}#{else}
		<a href="javascript:;" onclick="pick_submission(${sub.id});">Pick this submission for grading</a>
		#{/else}
		</div>
	</li>
#{/list}
	<li><a href="javascript:;" onclick="$('#new_sub').toggle();">Submit a new submission</a>
	<div id="new_sub" style="display:none;">
		<form action="@{Submissions.submitNew(assignment.id)}" enctype="multipart/form-data" method="POST">
			<input type="file" name="file" /> <input type="submit" value="Submit" /> 
		</form>
	</div>
	</li>
</ol>
<script type="text/javascript">
function pick_submission(submissionId) {
	$.post('@{Ajax.pickSubmission()}', {submissionId: submissionId}, function(){
		location.reload();
	});
}
</script>